#!/bin/bash
#pMusic - external menu
#GPL - Copyright Sigmund Berglund

export TEXTDOMAIN=pmusic
export OUTPUT_CHARSET=UTF-8
SF='space-expand="false" space-fill="false"'
ST='space-expand="true" space-fill="true"'


template(){
	echo '
	<eventbox above-child="true" visible-window="true">
	 <hbox spacing="7" border-width="3">
	  <pixmap '$SF'><height>18</height><input file>'$APPDIR'/themes/'$THEME'/'$3'</input></pixmap>
	  <text xalign="0" '$ST'>
	   <label>'$1'</label>
	  </text>
	 </hbox>
	 <action signal="enter-notify-event">hide:'$2'</action>
	 <action signal="enter-notify-event">show:'$2'B</action>
	 <variable>'$2'</variable>
	</eventbox>
	<eventbox name="rightclick_menu" above-child="true" visible-window="true" visible="false">
	 <hbox spacing="7" border-width="3">
	  <pixmap '$SF'><height>18</height><input file>'$APPDIR'/themes/'$THEME'/'$3'</input></pixmap>
	  <text xalign="0" '$ST'>
	   <label>'$1'</label>
	  </text>
	 </hbox>
	 <action signal="leave-notify-event">show:'$2'</action>
	 <action signal="leave-notify-event">hide:'$2'B</action>
	 <action signal="button-release-event">EXIT:'$2'</action>
	 <variable>'$2'B</variable>
	</eventbox>
	'
}

export gtkdialog_menu='
<window decorated="false" border-width="0" skip_taskbar_hint="true" resizable="false" modal="true" '$ST'>
 <eventbox name="rightclick_menu_frame" above-child="false">
  <vbox border-width="1">
   <eventbox>
    <vbox spacing="0" border-width="7">
     '"
     $(template " $(gettext 'Follow playque')" straight icon_playmode_straight.svg)
     $(template " $(gettext 'Repeat list after last track')" loop icon_playmode_loop.svg)
     $(template " $(gettext 'Play a random track')" shuffle icon_playmode_shuffle.svg)
     $(template " $(gettext 'Stop after this track')" stop icon_playmode_stop.svg)
     "'
    </vbox>
   </eventbox>
  </vbox>
 </eventbox>
 <action signal="focus-out-event">EXIT:exit</action>
</window>'

I=$IFS; IFS=""
for STATEMENTS in $($GTKDIALOG -p gtkdialog_menu -G +"$(($PTR_X_ROOT-190))"+"$(($PTR_Y_ROOT-70))"); do
	eval $STATEMENTS
done
IFS=$I

if [[ "$EXIT" = @(straight|loop|shuffle|stop) ]]; then
	echo "$EXIT" > $WORKDIR/PLAYMODE
	cp -f $APPDIR/themes/$THEME/icon_playmode_"$EXIT".svg $WORKDIR/icon_playmode.svg
fi